package com.supermap.originTest;



import com.supermap.data.*;
import com.supermap.data.processing.*;
import com.supermap.realspace.CacheFileType;

/**
 * @DESC： 切osgb三维缓存（scp）
 * @DATE: 2024-04-07  11:26
 * @Author: lc
 * @Version: 1.0
 */

public class BuildOsgbCache  {
    public static final int DEFAULT_THREAD = 12;
    public static final String METADATA_XML = "metadata.xml";
    public static final String DATA = "Data";


    public static void main(String[] args) {
        buildOsgbCache();

    }


    public static boolean buildOsgbCache() {
        //scp文件路径
        String scpFullPath = "E:\\MapData\\202408\\傾斜20\\組件人民检察院生成scp文件\\terra_osgbs\\terra_osgbs.scp";
        //生成缓存文件路径
        String outputFullFolder = "E:\\MapData\\202408\\傾斜20\\new\\j449013011";
        boolean flag = false;
        ObliquePhotogrammetryBuilder obliquePhotogrammetryBuilder = new ObliquePhotogrammetryBuilder(
                new ObliqueProcessType[]{ObliqueProcessType.COMPRESS_TEXTURE,ObliqueProcessType.COMBINE_NODE});
        //设置中心点坐标单位。
        obliquePhotogrammetryBuilder.setCenterPositionUnit(DataUnit.Meter);
        //设置置重建指数
        obliquePhotogrammetryBuilder.setCombineLevel(3);
        //设置重建类型
        obliquePhotogrammetryBuilder.setCombineNodeType(CombineNodeType.ALL);
        //设置结果数据的缓存文件格式
        obliquePhotogrammetryBuilder.setFileType(CacheFileType.S3MB);



        //设置存储类型，包括原始型和紧凑型
        obliquePhotogrammetryBuilder.setStorageType(StorageType.Original);
        //设置版本
        obliquePhotogrammetryBuilder.setS3MVersion(S3MVersion.VERSION_30);
        //设置坐标系
        obliquePhotogrammetryBuilder.setTargetPrjCoordSys(new PrjCoordSys(4490));
        //设置转换参照系，倾斜入库，设置目标坐标系时使用。
        obliquePhotogrammetryBuilder.setTargetCoordSysCoordSysTransMethod(CoordSysTransMethod.MTH_GEOCENTRIC_TRANSLATION);
        //设置转换参照系转换参数，倾斜入库，设置目标坐标系时使用。
        obliquePhotogrammetryBuilder.setTargetCoordSysTransParameter(new CoordSysTransParameter());
        //设置纹理压缩类型
        obliquePhotogrammetryBuilder.setTexCompressType(TextureCompressType.TEXTURECOMPRESS_CRNDXT5);
        //设置根节点的着色类型。
        obliquePhotogrammetryBuilder.setRootNodeColorType(RootNodeColorType.RCT_TEXTUREANDVERTEXCOLOR);
        //设置几何压缩方式，包括不压缩、常规压缩、DRACO压缩
        obliquePhotogrammetryBuilder.setVertexOptimazationType(VertexOptimizationType.VO_MESHOPT);
        //添加进度监听
        SteppedListener steppedListener = new SteppedListener() {
            @Override
            public void stepped(SteppedEvent steppedEvent) {
                String message = steppedEvent.getTitle() + "：" + steppedEvent.getMessage() + "：" + steppedEvent.getPercent() + "%";
                System.out.println("切OSGB缓存进度：{}"+ message);
            }
        };
        obliquePhotogrammetryBuilder.addSteppedListener(steppedListener);
        try {
            flag = obliquePhotogrammetryBuilder.build(scpFullPath, outputFullFolder, 4);

            System.err.println("切OSGB缓存是否成功:{}"+ flag);
            return flag;
        } catch (Exception e) {
            System.err.println("切OSGB缓存错误："+ e);
            throw e;
        } finally {
            obliquePhotogrammetryBuilder.removeSteppedListener(steppedListener);
            obliquePhotogrammetryBuilder.dispose();
        }
    }

}
